<!DOCTYPE html>
<html lang="zh-CN">
<style type="text/css">
    .title4 {
        color: #fafafa;

        letter-spacing: 0;

        font-size: 50px;

        text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135;

    }

    .box {
        background-color: #FFF;
        border-radius: 5px;
        border: 1px solid #DDD;
        padding: 30px 20px;
        margin: 50px 10% 20px 10%;
        width: 80%;
        height: 100%;
        text-align: center;

    }

    .box:hover {
        box-shadow: 0 0 5px 3px #CCC;
    }

    .table11_7 table {
        width: 100%;
        margin: 15px 0;
        border: 0;
    }

    .table11_7 th {
        background-color: #00A5FF;
        color: #FFFFFF
    }

    .table11_7,
    .table11_7 th,
    .table11_7 td {
        font-size: 0.95em;
        text-align: center;
        padding: 4px;
        border-collapse: collapse;
    }

    .table11_7 th,
    .table11_7 td {
        border: 1px solid #2087fe;
        border-width: 1px 0 1px 0;
        border: 2px inset #ffffff;
    }

    .table11_7 tr {
        border: 1px solid #ffffff;
    }

    .table11_7 tr:nth-child(odd) {
        background-color: #aae1fe;
    }

    .table11_7 tr:nth-child(even) {
        background-color: #ffffff;
    }
</style>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>新闻详情</title>

    <link rel="stylesheet" href="../../Public/Css/index.css">
</head>

<body>


    <nav class="navbar">
        <div class="container navbar-content">
            <ul id="menu">
                <li>
                    <a href=""> 首页</a>
                </li>
                <li>
                    <a href=""> 排行</a>
                </li>
                <li>
                    <a href=""> 分类浏览</a>
                </li>
                <li>
                    <a href=""> 所有新闻</a>
                </li>
                <li>
                    <a href=""> 所有新闻</a>
                </li>
        </div><!-- /.container-fluid -->
    </nav>
    <h1 align="center" class="title4">&nbsp;&nbsp;&nbsp;新闻发布系统</h1>
    <div class="box">
        <h2>新闻详情</h2>
        <form action="../Review/Add_C.php" method="POST" enctype="multipart/form-data">
            <?php
            include_once("../../Functions/connectDatabase.php");
            get_connection();
            $id = $_REQUEST["id"];
            $sql = "SELECT * FROM news WHERE news_id='$id'";
            $result = mysqli_query($conn, $sql);
            if (mysqli_num_rows($result) > 0) {
                $row = mysqli_fetch_assoc($result);
                echo "标题：<input type=\"text\" name=\"title\" value=\"" . $row['news_title'] . "\"><br><br>";
                echo "发表时间：" . $row['news_publish_time'] . "<br><br>";
                $sql = "SELECT category_name FROM category WHERE category_id='" . $row['category_id'] . "'";
                $result = mysqli_query($conn, $sql);
                $r2 = mysqli_fetch_assoc($result);
                echo "类别：" . $r2['category_name'] . "<br><br>";
                $sql = "SELECT user_name FROM users WHERE user_id='" . $row['user_id'] . "'";
                $result = mysqli_query($conn, $sql);
                $r1 = mysqli_fetch_assoc($result);
                echo "发布者：" . $r1['user_name'] . "<br><br>";
                echo "内容：<textarea readonly=\"readonly\">" . $row['news_content'] . "</textarea><br><br>";
                echo "附件：<a href=\"../../Functions/download.php?attachment=" . $row['news_attachment'] . "\">" . $row['news_attachment'] . "</a>";
                echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"10485760\">";
                echo "<input type=\"hidden\" name=\"id\" value=\"$id\">";
                $sql = "SELECT * FROM review WHERE news_id ='".$row['news_id']."'";
                $re = mysqli_query($conn, $sql);
                $total_records = mysqli_num_rows($re);
                $page_size = 5;
                if(isset($_GET["page_current"])){
                    $page_current = $_GET["page_current"];
                }else{
                    $page_current = 1;
                }
                $start = ($page_current-1)*$page_size;
                $sql = "SELECT * FROM review WHERE news_id ='".$row['news_id']."' order by news_id desc limit $start,$page_size";
                $re = mysqli_query($conn, $sql);
                echo "<table align=\"center\" class=table11_7 width=\"500\">";
                echo "<br><br><tr><th>用户</th><th>发布时间</th><th>评论内容</th></tr>";
                if (mysqli_num_rows($re) > 0) {
                    while ($r1 = mysqli_fetch_assoc($re)) {
                        if($r1['review_state'] == "通过"){
                        echo "<tr>";
                        $sql = "SELECT user_name FROM users WHERE user_id='" . $r1['user_id'] . "'";
                        $res = mysqli_query($conn, $sql);
                        $r2 = mysqli_fetch_assoc($res);
                        echo "<td>" . $r2["user_name"] ."</td>";
                        echo "<td>" . $r1["review_publish_time"] . "</td>";
                        echo "<td>" . $r1["review_content"] . "</td>";
                        echo "</tr>";
                        }
                    }
                } else {
                    echo "<tr><td colspan=\"3\">暂无评论</td><tr>";
                }
                echo "</table>";
                echo "<br><br>";
                echo "发表评论：<textarea cols=\"60\" rows=\"2\" name=\"content\" placeholder=\"说两句吧...\"></textarea><br><br>";
                echo "<input type=\"submit\" value=\"发 表\" />";
                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo "<input type=\"reset\" value=\"重 填\" />";
                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo "<button type=\"button\" onclick=\"javascript:history.back(-1);\">返回上一页</button>";
                $clicked = $row["news_clicked"]+1;
                $sql = "UPDATE news SET news_clicked='".$clicked."'WHERE news_id='$id'";
                mysqli_query($conn, $sql);
            } else {
                echo "<h1>404 NOT FOUND</h1>";
                echo "<button type=\"button\" onclick=\"javascript:history.back(-1);\">返回上一页</button>";
            }
            ?>


        </form>
    </div>

</body>

</html>